/************************************************************************/
/* Core                                                                 */
/************************************************************************/
#include "Core/Timer.h"


namespace TD_Core {

	Timer::Timer() {
		//Initialize the variables 
		startTicks = 0; 
		pausedTicks = 0; 
		paused = false; 
		started = false;
	}

	void Timer::start() {
		//Start the timer 
		started = true; 
		//Unpause the timer 
		paused = false; 
		//Get the current clock time 
		startTicks = SDL_GetTicks(); 
	}

	void Timer::stop() { //Stop the timer
		started = false; //Unpause the timer
		paused = false; 
	}

	 int Timer::getTicks()
	{
		//If the timer is running
		if( started == true )
		{
			//If the timer is paused
			if( paused == true )
			{
				//Return the number of ticks when the timer was paused
				return pausedTicks;
			}
			else
			{
				//Return the current time minus the start time
				return SDL_GetTicks() - startTicks;
			}    
		}

		//If the timer isn't running
		return 0;    
	}
	
	void Timer::pause()
	{
		//If the timer is running and isn't already paused
		if( ( started == true ) && ( paused == false ) )
		{
			//Pause the timer
			paused = true;

			//Calculate the paused ticks
			pausedTicks = SDL_GetTicks() - startTicks;
		}
	}

	void Timer::unpause()
	{
		//If the timer is paused
		if( paused == true )
		{
			//Unpause the timer
			paused = false;

			//Reset the starting ticks
			startTicks = SDL_GetTicks() - pausedTicks;

			//Reset the paused ticks
			pausedTicks = 0;
		}
	}



}